// 例子: 图书的索引
// - 书名: 支持全文和精确匹配
// - 简介: 支持全文
// - 作者: 精确值
// - 发行日期: 日期类型
// - 图书封面: 精确值

DELETE books

PUT books
{
      "mappings" : {
      "properties" : {
        "author" : {"type" : "keyword"},
        "cover_url" : {"type" : "keyword","index": false},
        "description" : {"type" : "text"},
        "public_date" : {"type" : "date"},
        "title" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 100
            }
          }
        }
      }
    }
}

// 新需求: 增加图书内容, 并要求能被搜索到同时高亮
// 分析: 新需求会导致 _source 内容过大, source filter 只是传输给客户端的时候进行过滤, fetch的时候es节点还是会传输_source
// 解决办法: 关闭 _source, 然后每个字段的store设置为true
PUT books
{
    "mappings": {
        "_source": {"enabled": false},
        "properties": {
            "author": {"type": "keyword","store": true},
            "cover_url": {"type": "keyword","index": false,"store": true},
            "description": {"type": "text","store": true},
            "content": {"type": "text","store": true},
            "public_date": {"type": "date","store": true},
            "title": {
                "type": "text", 
                "fields": {"keyword": {"type": "keyword","ignore_above": 100}},
                "store": true
            }
        }
    }
}

PUT books/_doc/1
{
  "title":"Mastering ElasticSearch 5.0",
  "description":"Master the searching, indexing, and aggregation features in ElasticSearch Improve users’ search experience with Elasticsearch’s functionalities and develop your own Elasticsearch plugins",
  "content":"The content of the book......Indexing data, aggregation, searching.    something else. something in the way............",
  "author":"Bharvi Dixit",
  "public_date":"2017",
  "cover_url":"https://images-na.ssl-images-amazon.com/images/I/51OeaMFxcML.jpg"
}

// 查询结果中，没有 _source
GET books/_search

GET books/_search
{
  "stored_fields": ["title","author","public_date"],
  "query": {
    "match": {
      "content": "searching"
    }
  },

  "highlight": {
    "fields": {
      "content":{}
    }
  }
}
